package cn.ilikes.tools.nosql.jpa.configs.envs.pus;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.slf4j.Logger;

import cn.ilikes.tools.logs.Loggerfactory;
import cn.ilikes.tools.nosql.jpa.JPASQLPersistenUnitEnv;
import cn.ilikes.tools.nosql.jpa.configs.envs.JPASQLConfigurationException;

public class PersistenceUnitConfigure implements IConfigure {

	private static Logger logger = Loggerfactory.instance(PersistenceUnitConfigure.class);
	private Properties properties;
	private List<IConfigure> configures = new ArrayList<IConfigure>();

	public PersistenceUnitConfigure(Properties properties) {
		this.properties = properties;
		init();
	}

	private void addIConfigure(IConfigure configure) {
		configures.add(configure);
	}

	/**
	 * config 初始化
	 */
	private void init() {

		PersistenceIEntityMetaDataFactoryConfigure entityMetaDataFactoryConfigure = new PersistenceIEntityMetaDataFactoryConfigure(properties);
		addIConfigure(entityMetaDataFactoryConfigure);
	}

	@Override
	public void config(String persistenUnitName, JPASQLPersistenUnitEnv persistenUnitEnv) throws JPASQLConfigurationException {
		Loggerfactory.info(logger, "JPA HBase Start Configure Persistence Units Name : " + persistenUnitEnv.getPersistenUnitName());
		for (IConfigure configure : configures) {
			configure.config(persistenUnitName, persistenUnitEnv);
		}
		persistenUnitEnv.init();

	}

}
